Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class frmCASH

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub frmCASH_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmCASH_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Control.CheckForIllegalCrossThreadCalls = False
       Thread_PrintKitchen
    End Sub
    Private Sub Thread_PrintKitchen()
        Dim rptDocument As ReportDocument
        Dim pvCollection As New CrystalDecisions.Shared.ParameterValues
        Dim BILL_CODE As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim PRINTER_NAME As New CrystalDecisions.Shared.ParameterDiscreteValue

        Dim ConStr As String = PublicVariable.ReportConnectionString

        Dim MyArr As Array = ConStr.Split(";")
        ' Create a report document instance to hold the report

        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table
        Try
            ' Load the report 
            Dim rptRedInvoice As New ReportDocument
            rptRedInvoice.Load(Application.StartupPath + "\Report\Cash.rpt")

            'Set DB con
            With crConnectionInfo
                .ServerName = MyArr(0)
                .DatabaseName = MyArr(1)
                .UserID = MyArr(2)
                .Password = MyArr(3)
            End With

            'Apply DB con
            CrTables = rptRedInvoice.Database.Tables

            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
                CrTable.Location = CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)

            Next
            'BILL_CODE.Value = ""
            'pvCollection.Add(BILL_CODE)
            'rptRedInvoice.DataDefinition.ParameterFields("@BILL_CODE").ApplyCurrentValues(pvCollection)

            'PRINTER_NAME.Value = ""
            'pvCollection.Add(PRINTER_NAME)
            'rptRedInvoice.DataDefinition.ParameterFields("@PRINTER").ApplyCurrentValues(pvCollection)

            Dim doctoprint As New System.Drawing.Printing.PrintDocument()
            CrystalReportViewer1.ReportSource = rptRedInvoice
            rptRedInvoice.PrintOptions.PaperSize = PaperSize.PaperA4
            CrystalReportViewer1.ReportSource = rptRedInvoice

            rptDocument = rptRedInvoice
            CrystalReportViewer1.Visible = True
            CrystalReportViewer1.Show()

        Catch Exp As Exception
            MessageBox.Show(Exp.Message)
        End Try
    End Sub
End Class